/*
 * mg90s.c
 *
 *  Created on: 2024 Jun 26
 *      Author: simeonidi03
 */
#include"mg90s.h"

void servo_val_set(size_t value, uint16_t timer_period, uint8_t servo_number){
	if(value > 255 || value < 0){return;}

	uint16_t new_value = NULL_SERVO + (value * 100) / 255 ;
	new_value = (uint16_t)(((uint32_t) new_value * (timer_period- 1)) / 1000);
	if(servo_number == 1){
		tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_4, new_value);
	}else if(servo_number == 2){
		tmr_channel_value_set(TMR3, TMR_SELECT_CHANNEL_3, new_value);
	}
}
